<?php
class Exts_Services_SecureService 
{
	protected $_userparam = "user";
	protected $_certificateparam = "certificate";
	protected $_certificate = NULL;
	protected $_user = NULL;
	

	public function __construct () {
		$this->init();
	}
	public function init()   {
	}
	
	/**
	 * @param mixed $cryptedUser usuario encriptado 
	 * @return mixed $certificado que debe ser usado para los metodos seguros.
	 * */
	public function validateUser ($cryptedUser) {

		$secureUser = Exts_Security_SecureUser::Load($cryptedUser);
		
		$decrypt = new Zend_Filter_Decrypt(
		array( 'adapter' => 'mcrypt', 'vector' => 'myvector')
		);
		
		if($secureUser->validateUser()){
			return $secureUser->makeCertificate()->getSecureData();
		}
		
		return "invalid certificate";
	}
	
	protected function _validateCertificate($certificate) {
		$this->_certificate = Exts_Security_Certificate::Load($certificate);
		if ($this->_certificate->validateCertificate()){
			$this->_user = $this->_certificate->getUser();
			return true;
		}
		return false;
	} 
	
	public function getUser () {
		if ($this->_certificate == NULL) {
			throw new Exts_Exception ("¡El servicio no tiene un certificado asociado!");
		}
		return $this->_certificate->getUser();
	}
	
}
